package agency.tango.materialintroscreen.listeners.clickListeners;

import agency.tango.materialintroscreen.widgets.BottomSnackBar;
import ohos.agp.components.Component;

import agency.tango.materialintroscreen.animations.ViewTranslationWrapper;
import agency.tango.materialintroscreen.slice.MaterialIntroSlice;


/**
 * @ProjectName: material-intro-screen-master
 * @Package: agency.tango.materialintroscreen.listeners.clickListeners
 * @ClassName: PermissionNotGrantedClickListener
 * @Description: 权限没有申请点击监听器实现类
 * @CreateDate: 2021/4/12 16:41
 * @UpdateDate: 2021/4/12 16:41
 * @UpdateRemark: 暂无
 * @Version: 1.0
 */
public class PermissionNotGrantedClickListener implements Component.ClickedListener {
    private final MaterialIntroSlice activity;
    private final ViewTranslationWrapper translationWrapper;
    private long clickTime = 0; // 防止过快点击出现BUG
    private BottomSnackBar snackBar; // snackBar;

    public PermissionNotGrantedClickListener(MaterialIntroSlice activity, ViewTranslationWrapper translationWrapper) {
        this.activity = activity;
        this.translationWrapper = translationWrapper;
    }

    public void setSnackBar(BottomSnackBar snackBar) {
        this.snackBar = snackBar;
    }

    @Override
    public void onClick(Component component) {
        //snackBar显示的时候不再响应点击事件
        if (snackBar != null && snackBar.getBuilder() != null) {
            if (System.currentTimeMillis() - clickTime <= snackBar.getBuilder().getDuration()
                    || snackBar.isShow()) {
                return;
            }
        }
        clickTime = System.currentTimeMillis();
        if (translationWrapper != null) {
            translationWrapper.error();
        }
        if (activity != null) {
            activity.showPermissionsNotGrantedError();
        }
    }
}
